package controllers.caterinaController.controllers;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import budget.Request;

import controllers.mail.models.CModels;

import person.Employee;
import person.Person;



public class MailManager {
	public static boolean sendMail(String mailSubject,String mailText,String by,String to){
	    try{
			String smtpHost = "out.virgilio.it";
	    	Properties props = System.getProperties ();
	    	props.put ("mail.smtp.host", smtpHost);
	    	Session session = Session.getDefaultInstance (props, null);
	    	MimeMessage message = new MimeMessage (session);
	    	message.setContent(mailText, "text/html; charset=utf-8");
	    	message.setFrom (new InternetAddress (by));
	    	message.addRecipient (Message.RecipientType.TO, new InternetAddress (to));
	    	message.setSubject (mailSubject);
	    	Transport.send (message);
	    	return true;
	    }
	    catch (Exception e){
	    	return false;
	    }
	}
	public static boolean sendRequestAccepted(Employee emp,Request req){
		return sendMail("Accettazione evento",CModels.getRequestAcceptedModel(emp, req),emp.getEmail(),req.getCustomer().getEmail());
	}
	public static boolean sendRegistrationConfirmation(Person person,String username,String password){
		return sendMail("Caterina-Registrazione",CModels.getRegisterMailModel(person, username, password) ,"no-reply@caterina.org", person.getEmail());
	}
	public static boolean sendRequestAcceptedMail(Request req){
		return true;
	}
}
